<?php
session_start();
if (isset($_GET['logout'])){
	$_SESSION['login'] = "";
}
	

$errStr = "";
$data = null;
$isLoggedIn = false;
if (isset($_POST['name']) && isset($_POST['passwd'])) {
	$name = $_POST['name'];
	$passwd = $_POST['passwd'];
	$json_string = file_get_contents('/link/config/passwd.json');
	$data = json_decode($json_string, true);

	for ($i = 0; $i < count($data); $i++) {
		
		if ($data[$i]["name"] == $name && $data[$i]["passwd"] == md5($passwd)) {
			$_SESSION['login'] = $name;
			$isLoggedIn = true;
			break; // Once logged in, no need to continue checking
		}
	}
}


if ($isLoggedIn) {
	header('Content-Type: application/json');
	$jsonData = json_encode(array(
		'code' => 200,
		'data' => '',
		'msg' => '登录成功'
	));
	echo $jsonData;
} else {
	header('Content-Type: application/json');
	$jsonData = json_encode(array(
		'code' => 500,
		'data' => '',
		'msg' => '账号或密码错误'
	));
	echo $jsonData;
}

?>